<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>test</title>
</head>
<body>
    <h1>小小</h1>

    <script>
        // 前端获取请求
        // fetch('http://localhost:8080/info').then(res => res.json().then(res => console.log(res))) // 默认是get请求
        // fetch('http://localhost:8080/info', {
        //     method: 'PATCH',
        // }).then(res => res.json()).then(res => console.log(res)) 
        // fetch('http://localhost:8080/info', {
        //     method: 'POST',
        //     headers: {
        //         'Content-Type': 'application/json'
        //     },
        //     body: JSON.stringify({abc: '123'})
        // }).then(res => res.json()).then(res => console.log(res))
        fetch('http://localhost:8080/info').then(res => {
            const headers = res.headers
            console.log(headers.get('custom'));
            res.json()
        }).then(res => console.log(res)) // 默认是get请求

        // 单工通讯 sse, 需要用EventSource接收
        const sse = new EventSource('http://localhost:8080/sse')
        // 默认是监听message，后台可以改
        sse.addEventListener('message', (e) => {
            console.log(e.data)
        })
        sse.addEventListener('test', (e) => {   // 可以监听多个
            console.log(e.data)
        })
    </script>
</body>
</html>